﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using JX.Infrastructure.Attribute;
using JX.Infrastructure.Common;

namespace JX.Core.Entity
{
	/// <summary>
	/// 数据库表：Contacter 的实体类.
	/// </summary>
	public partial class ContacterEntity
	{
		private IList<EmergencyContactEntity> m_EmergencyContactList;
		/// <summary>
		/// 紧急联系人列表
		/// </summary>
		[NotMapped]
		public IList<EmergencyContactEntity> EmergencyContactList
		{
			get
			{
				if (m_EmergencyContactList == null)
				{
					if (!string.IsNullOrEmpty(EmergencyContact))
					{
						m_EmergencyContactList = EmergencyContact.ToJsonObject<IList<EmergencyContactEntity>>();
					}
				}
				return m_EmergencyContactList;
			}
		}

		private FamilyEntity m_FamilyEntity;
		/// <summary>
		/// 家庭情况实体类
		/// </summary>
		[NotMapped]
		public FamilyEntity FamilyEntity
		{
			get
			{
				if (m_FamilyEntity == null)
				{
					if (!string.IsNullOrEmpty(Family))
					{
						m_FamilyEntity = Family.ToJsonObject<FamilyEntity>();
					}
				}
				return m_FamilyEntity;
			}
		}

		/// <summary>
		/// 联系人扩展数据，数据格式：FieldName,FieldValue,FieldType,FieldLevel
		/// </summary>
		[NotMapped]
		public DataTable Fields { get; set; }
	}

	/// <summary>
	/// 紧急联系人实体类
	/// </summary>
	public class EmergencyContactEntity
	{
		/// <summary>
		/// 姓名
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string Name { get; set; } = string.Empty;

		/// <summary>
		/// 电话
		/// </summary>
		[RegularExpression(RegexHelper.MobilePattern, ErrorMessage = "格式不对")]
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string Tel { get; set; } = string.Empty;

		/// <summary>
		/// 身份证
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		[RegularExpression(RegexHelper.IdCardPattern, ErrorMessage = "格式不对")]
		public string IdCard { get; set; } = string.Empty;

		/// <summary>
		/// 家庭住址
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string HomeAddress { get; set; } = string.Empty;

		/// <summary>
		/// 单位名称
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string CompanyName { get; set; } = string.Empty;

		/// <summary>
		/// 单位地址
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string CompanyAddress { get; set; } = string.Empty;

		/// <summary>
		/// 与本人关系
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string Relationship { get; set; } = string.Empty;
	}

	/// <summary>
	/// 家庭情况实体类
	/// </summary>
	public class FamilyEntity
	{
		/// <summary>
		/// 家庭地址
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string Address { get; set; } = string.Empty;

		/// <summary>
		/// 家庭电话
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string Tel { get; set; } = string.Empty;

		/// <summary>
		/// 家庭人口数
		/// </summary>
		public int? Num { get; set; }

		/// <summary>
		/// 家庭月收入
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string Income { get; set; } = string.Empty;

		/// <summary>
		/// 人均月收入
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string AveIncome { get; set; } = string.Empty;

		/// <summary>
		/// 邮政编码
		/// </summary>
		[DisplayFormat(ConvertEmptyStringToNull = false)]
		public string ZipCode { get; set; } = string.Empty;

	}
}
